<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="案号" prop="ah">
        <el-input
          v-model="queryParams.ah"
          placeholder="请输入案号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="todoListList" @selection-change="handleSelectionChange">
      <el-table-column label="案号" align="center" prop="ah" />
      <el-table-column label="代表事项内容" align="center" prop="dbsxnr" />
      <el-table-column label="经办法院名称" align="center" prop="jbfyMc" />
      <el-table-column label="开庭时间" align="center" prop="ktsj" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['fs:todoList:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['fs:todoList:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改代办事项对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="案号" prop="ah">
          <el-input v-model="form.ah" placeholder="请输入案号" />
        </el-form-item>
        <el-form-item label="标号" prop="bh">
          <el-input v-model="form.bh" placeholder="请输入标号" />
        </el-form-item>
        <el-form-item label="案件名称" prop="ajmc">
          <el-input v-model="form.ajmc" placeholder="请输入案件名称" />
        </el-form-item>
        <el-form-item label="标号案件" prop="bhAj">
          <el-input v-model="form.bhAj" placeholder="请输入标号案件" />
        </el-form-item>
        <el-form-item label="代办事项类型" prop="dbsxlx">
          <el-select v-model="form.dbsxlx" placeholder="请选择代办事项类型">
            <el-option
              v-for="dict in dict.type.fs_gw_dbsxlx"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="代表事项内容" prop="dbsxnr">
          <el-input v-model="form.dbsxnr" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="经办法院id" prop="jbfy">
          <el-input v-model="form.jbfy" placeholder="请输入经办法院id" />
        </el-form-item>
        <el-form-item label="经办法院名称" prop="jbfyMc">
          <el-input v-model="form.jbfyMc" placeholder="请输入经办法院名称" />
        </el-form-item>
        <el-form-item label="交费类型" prop="jflx">
          <el-input v-model="form.jflx" placeholder="请输入交费类型" />
        </el-form-item>
        <el-form-item label="截止时间" prop="jzsj">
          <el-input v-model="form.jzsj" placeholder="请输入截止时间" />
        </el-form-item>
        <el-form-item label="开庭时间" prop="ktsj">
          <el-input v-model="form.ktsj" placeholder="请输入开庭时间" />
        </el-form-item>
        <el-form-item label="信息" prop="message">
          <el-input v-model="form.message" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="url" prop="url">
          <el-input v-model="form.url" placeholder="请输入url" />
        </el-form-item>
        <el-form-item label="网上开庭" prop="wskt">
          <el-input v-model="form.wskt" placeholder="请输入网上开庭" />
        </el-form-item>
        <el-form-item label="预计诉讼费金额" prop="yjssfje">
          <el-input v-model="form.yjssfje" placeholder="请输入预计诉讼费金额" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTodoList, getTodoList, delTodoList, addTodoList, updateTodoList } from "@/api/fs/todoList";

export default {
  name: "TodoList",
  dicts: ['fs_gw_dbsxlx'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 代办事项表格数据
      todoListList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ah: null,
        bh: null,
        ajmc: null,
        bhAj: null,
        dbsxlx: 2,
        dbsxnr: null,
        jbfy: null,
        jbfyMc: null,
        jflx: null,
        jzsj: null,
        ktsj: null,
        message: null,
        url: null,
        wskt: null,
        yjssfje: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询代办事项列表 */
    getList() {
      this.loading = true;
      listTodoList(this.queryParams).then(response => {
        this.todoListList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        ah: null,
        bh: null,
        ajmc: null,
        bhAj: null,
        dbsxlx: 2,
        dbsxnr: null,
        jbfy: null,
        jbfyMc: null,
        jflx: null,
        jzsj: null,
        ktsj: null,
        message: null,
        url: null,
        wskt: null,
        yjssfje: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加代办事项";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTodoList(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改代办事项";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTodoList(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTodoList(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除代办事项编号为"' + ids + '"的数据项？').then(function() {
        return delTodoList(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fs/todoList/export', {
        ...this.queryParams
      }, `todoList_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
